package com.buddy.learn.javasource._io.bio;

import java.io.IOException;
import java.net.Socket;

/**
 * @author Buddy
 * @date 2021/5/16
 */
public class BIOClinet {

    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost",9000);
            // 向服务端发送数据
            socket.getOutputStream().write("Hello BIO Server".getBytes());
            socket.getOutputStream().flush();
            System.out.println("向服务端发送数据结束");
            byte[] bytes = new byte[1024];
            // 接受服务端的响应
            socket.getInputStream().read(bytes);
            System.out.println("接收到的服务端的数据："+new String(bytes));
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
